package ca.usherbrooke.domus.sipnmove.useragent.controller;

import java.util.HashMap;
import java.util.Map;

import ca.usherbrooke.domus.sipnmove.call.Call;
import ca.usherbrooke.domus.sipnmove.call.CallFactory;
import ca.usherbrooke.domus.sipnmove.useragent.UserAgent;
import ca.usherbrooke.domus.sipnmove.useragent.view.UserAgentView;

/**
 * Call action controller
 */
public class CallActionController implements ActionController {

	/**
	 * User agent to control
	 */
	private UserAgent userAgent;

	/**
	 * User agent view to get information from
	 */
	private UserAgentView userAgentView;

	/**
	 * Call factory used to created new call
	 */
	private CallFactory callFactory;

	/**
	 * Do the controller action
	 */
	public void doAction()
	{
		Map<String, Object> callInformation = new HashMap<String, Object>();
		callInformation.put("address", this.userAgentView.getAddressTextField().getText());
		callInformation.put("initiated", true);
		
		Call call = callFactory.createCall(callInformation);
		userAgent.addCall(call);
		
		call.initiate(callInformation);
	}

	/**
	 * @return the userAgent
	 */
	public UserAgent getUserAgent() {
		return userAgent;
	}

	/**
	 * @param userAgent the userAgent to set
	 */
	public void setUserAgent(UserAgent userAgent) {
		this.userAgent = userAgent;
	}

	/**
	 * @return the userAgentView
	 */
	public UserAgentView getUserAgentView() {
		return userAgentView;
	}

	/**
	 * @param userAgentView the userAgentView to set
	 */
	public void setUserAgentView(UserAgentView userAgentView) {
		this.userAgentView = userAgentView;
	}

	/**
	 * @return the callFactory
	 */
	public CallFactory getCallFactory() {
		return callFactory;
	}

	/**
	 * @param callFactory the callFactory to set
	 */
	public void setCallFactory(CallFactory callFactory) {
		this.callFactory = callFactory;
	}
	
}
